authApp.value('page','material_apply'); 
authApp.controller("applySLMController",function($scope,$http,$location,$getQueryString,$splice, $cookies){
	$scope.preNum=$getQueryString("preNum");
	$scope.isAddM=true;
	$scope.showEdit = false;
	//var requestJson={'pageNumber':'0','pageSize':'10','fid':$getQueryString("pid"),'type':'1'};
	var requestJson={'pid':$getQueryString("pid")};
	$scope.sites = [{
	key: 2,
	  site: '现代化学校'
	}, {
	key: 2,
	  site: '优质学校'  
	}]
	$scope.schools = 0;
	$scope.addM=function(){
		$scope.isAddM=false;
	}

	$scope.show = function(num) {
		var el = document.getElementById(num)
		if (el.style.display == 'none') {
			el.style.display = 'block'
		} else {
			el.style.display = 'none'
		}
	  }
	$scope.cancelAddM=function(){
		$scope.isAddM=true;
		$scope.addFZ="";
		$scope.addFZNum="";
		$scope.zbMajor="";
		$scope.addBZ="";
	}
	$scope.addFirstZ=function(){
		if(window.confirm("是否确认添加？")){
			if($scope.addFZ){
				var rJson={'name':$scope.addFZ,'indexId':$getQueryString("pid")};
				$http({
					method:'post',
					url:apis.saveSonTarget,
					data:rJson,
				}).success(function(response){
					if(response.code=="000000"){
						$scope.isAddM=true;
						$scope.getAML();
						$scope.addFZ="";
					}
				}).error(function(){
					alert("服务器打瞌睡了，请稍等！");
					$scope.isAddM=true;
				})
			}else{
				alert("请输入二级指标标题");
			}
		}
	}
	//编辑
	$scope.edit = function (item) {
        $scope.item = item;
        $scope.showEdit = true;
    }
    $scope.doEdit = function (item) {
		/*if(!item.number){
			alert("请填写序号");
			return;
		}
		if(!item.major){
			alert("请选择专业");
			return;
		}*/
		if(!item.s_name) {
			alert("请输入二级指标标题");
			return;
		}
		/*if(!item.standards) {
			alert("请输入二级指标标准");
			return;
		}*/
		var rJson={'name':item.s_name,'pid':item.p_id};
		$http({
			method:'post',
			url:apis.updataSonTarget,
			data:rJson,
		}).success(function(response){
			if(response.code=="000000"){
                alert("编辑成功");
				$scope.showEdit=false;
				$scope.getAML();
				$scope.item="";
			}
		}).error(function(){
			alert("服务器打瞌睡了，请稍等！");
			$scope.showEdit=false;
		})
    }
    $scope.doCancel = function () {
        $scope.showEdit=false;
    }
	$scope.getAML=function(){
		$http({
			method:'post',
			url:apis.querySonTargetByFid,
			data:requestJson,
		}).success(function(response){
			if(response.code=="000000"){
				$scope.list=response.data;
				angular.forEach($scope.list,function(data,index,array){
					data.number = index + 1;
					/*if(data.major=="0"){
					 data.majorName="学前教育";
					 }else if(data.major=="1"){
					 data.majorName="小学教育";
					 }else if(data.major=="2"){
					 data.majorName="中学教育";
					 }else{
					 data.majorName="未选择";
					 }*/
				});
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("服务器打瞌睡了，请稍等！");
		})
	}
	$scope.delCollect=function(pid){
		if(window.confirm("是否确定删除？")){
			var rJson={'pid':pid};
			$http({
				method:'post',
				url:apis.deleteSonTarget,
				data:rJson,
			}).success(function(response){
				if(response.code=="000000"){
					$scope.getAML();
				}else{
					alert(response.errorMsg);
				}
			})
		}
	}
	$scope.turnTo=function(pid,num,index){
		var ids = document.getElementById('sel'+index)
		ids = ids.value
		$cookies.put('ids', ids)
		location.href="m-detail.html?pid="+pid+"&preNum="+num+'&school_type=' + ids;
	}
	$scope.getAML();
})
	